// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
	env: cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database()
const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {
	// 获取传参过来的数据
	const {UID, post_time, formData, nickname, avatarUrl, userID} = event
	// 将formData的内容进行解构
	const {student_name, ID_card_No, location, contact_way} = formData
	// 此云函数是身份证提交云函数，设置默认数据
	const [tags, type, is_found] = ['lost', '身份证', false]
	const image = ['cloud://lost-and-found-7gyn2a47a633be5d.6c6f-lost-and-found-7gyn2a47a633be5d-1310485191/default_images/默认图片 - 身份证.png']
	
	return await db.collection('lost_and_found_infos').add({
		data:{
			UID,
			post_time,
			nickname,
			avatarUrl,
			student_name,
			ID_card_No,
			location,
			contact_way,
			tags,
			type,
			is_found,
			image,
			userID
		}
	})
}